package com.lyf.scm.plan.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * 线程池配置
 *
 * @author wangchlei
 * @date 2020/09/27
 */
@Configuration
public class ThreadPoolConfig {
    @Bean
    public ExecutorService sonExecutorService() {
        return getSonExecutorService();
    }

    /**
     * 线程池获取
     *
     * @param
     * @return {@link ExecutorService}
     **/
    private ExecutorService getSonExecutorService() {
        //核心线程池数量为一次处理的表的数量，队列大小先默认为3
        return new ThreadPoolExecutor(6,
                30,
                2,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(100),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());
    }
}
